/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package forms;

import com.sun.lwuit.Button;
import com.sun.lwuit.Font;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BoxLayout;
import com.sun.lwuit.plaf.Border;
import util.LwuitAppHelper;
import view.img.ImageStore;

/**
 *
 * @author ademar.victorino
 */
public class InicialForm extends AbstractForm {

    /**
     * @return the instance
     */
    public static InicialForm getInstance() {
        return instance;
    }
    private Button btnBusca = null;
    private Button btnConfig = null;
    private Button btnSair = null;
    private static InicialForm instance = new InicialForm();

    private InicialForm() {
        super("Desktop");
        setLayout(new BoxLayout(BoxLayout.Y_AXIS));

        addComponent(getBtnBusca());
        addComponent(getBtnConfig());
        addComponent(getBtnSair());
        /*Container cont1 = new Container(new FlowLayout(Component.CENTER));
        cont1.addComponent(new Label(ImageStore.getInstance().getImage("logo")));
        addComponent(cont1);*/

    }

    public Button getBtnBusca() {
        if (btnBusca == null) {

            btnBusca = new Button("Busca", ImageStore.getInstance().getImage("busca"));
            setDefaultBtnStyle(btnBusca);
            btnBusca.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {

                    buscaAction();

                }
            });
        }
        return btnBusca;
    }

    public void buscaAction() {

        WaitForm.getInstance().show();
        final AbstractForm f = this;
        Thread t = new Thread(new Runnable() {

            public void run() {
                new CategoriasRaizForm().show();
            }
        });
        t.start();

    }

    public Button getBtnSair() {
        if (btnSair == null) {
            btnSair = new Button("Sair", ImageStore.getInstance().getImage("sair"));
            setDefaultBtnStyle(btnSair);
            btnSair.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {
                    LwuitAppHelper.getInstance().exitMidlet();
                }
            });
        }

        return btnSair;
    }

    public Button getBtnConfig() {
        if (btnConfig == null) {
            btnConfig = new Button("Configuração", ImageStore.getInstance().getImage("configuracao"));
            setDefaultBtnStyle(btnConfig);
            btnConfig.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent arg0) {
                    new ConfigOperadoraForm(InicialForm.this).show();
                }
            });
        }

        return btnConfig;
    }
}
